﻿using DatabaseService.DatabaseDAO;
using System.Collections.Generic;
using System.Data;

namespace DatabaseService
{
    /// <summary>
    /// 数据库操作类
    /// </summary>
    public interface IDatabaseDAO
    {
        /// <summary>
        /// 数据库执行对象
        /// </summary>
        IDatabaseService databaseService { get; set; }

        #region Function
        /// <summary>
        /// 检查数据库链接
        /// </summary>
        /// <returns></returns>
        bool CheckDBconn();
        /// <summary>
        /// 是否存在记录
        /// </summary>
        /// <typeparam name="T">数据库表实体类</typeparam>
        /// <param name="parametersModel">参数实体类</param>
        /// <returns></returns>
        bool Exists<T>(DaoParametersEntity parametersModel) where T : TableModelMapper, new();
        /// <summary>
        /// 检验某表是否存在某字段名
        /// </summary>
        /// <param name="tableName">数据库表名</param>
        /// <param name="columnName">字段名</param>
        /// <returns></returns>
        bool ExistsColumn(string tableName, string columnName);
        #endregion

        #region 接口优化
        /// <summary>
        /// 修改记录
        /// </summary>
        /// <typeparam name="T">数据库表实体类</typeparam>
        /// <param name="parametersModel">参数实体类</param>
        /// <returns>sql执行影响的行数</returns>
        int Update<T>(DaoParametersEntity parametersModel) where T : TableModelMapper, new();
        /// <summary>
        /// 插入记录
        /// </summary>
        /// <typeparam name="T">数据库表实体类</typeparam>
        /// <param name="parametersModel">参数实体类</param>
        /// <returns>sql执行影响的行数</returns>
        int Insert<T>(DaoParametersEntity parametersModel) where T : TableModelMapper, new();
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <typeparam name="T">数据库表实体类</typeparam>
        /// <param name="parametersModel">参数实体类</param>
        /// <returns>sql执行影响的行数</returns>
        int Delete<T>(DaoParametersEntity parametersModel) where T : TableModelMapper, new();
        /// <summary>
        /// 查询
        /// </summary>
        /// <typeparam name="T">数据库表实体类</typeparam>
        /// <param name="parametersModel">参数实体类</param>
        /// <returns>IList<T> 结果集转化List</returns>
        IList<T> Select<T>(DaoParametersEntity parametersModel) where T : TableModelMapper, new();
        /// <summary>
        /// 查询值
        /// </summary>
        /// <typeparam name="T">数据库表实体类</typeparam>
        /// <typeparam name="T1">需要返回的类型</typeparam>
        /// <param name="parametersModel">参数实体类</param>
        /// <returns>sql执行的第一行第一列的值</returns>
        T1 Select_Value<T, T1>(DaoParametersEntity parametersModel) where T : TableModelMapper, new();
        /// <summary>
        /// 存储过程执行
        /// 返回结果集
        /// </summary>
        /// <param name="parametersModel">参数实体类</param>
        /// <returns>DataSet 过程执行结果集</returns>
        DataSet ExecuteProcGetDataSet(DaoParametersEntity parametersModel);

        /// <summary>
        /// 存储过程执行
        /// 返回结果集List
        /// 当每个结果集类型相同时使用
        /// </summary>
        /// <typeparam name="T">结果集实体类</typeparam>
        /// <param name="parametersModel">参数实体类</param>
        /// <returns>IList<T> 过程执行结果集转化List</returns>
        IList<T> ExecuteProcGetList<T>(DaoParametersEntity parametersModel) where T : ProcedureEntityMapper;
        #endregion
    }
}
